# -*- coding: utf-8 -*-

from django.db import models
from django.db.models import Model, Manager


class BaseModel(Model):
    delete_flag = models.BinaryField(default=0, max_length=1, verbose_name='是否删除',
                                     choices=((0, '未删除',), (1, '已删除'),), )
    delete_time = models.DateTimeField(verbose_name='删除时间', auto_now=True),

    create_time = models.DateTimeField(verbose_name='创建时间', auto_now=True)
    update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True)

    objects = Manager()

    class Meta:
        abstract = True
        pass

    def __str__(self):
        if hasattr(self, 'name'):
            return self.name
        return ''

    pass


class TableModel(BaseModel):
    char_field = models.CharField(max_length=32, )
    date_field = models.DateField(auto_now=True)
    date_time_field = models.DateTimeField(auto_now=True)
    integer_field = models.IntegerField()
    float_field = models.FloatField()
    decimal_field = models.DecimalField(max_digits=10, decimal_places=4)

    class Meta:
        db_table = 'dj_table'
        verbose_name = 'TableModel'
        verbose_name_plural = verbose_name
        pass

    pass


class School(BaseModel):
    school_id = models.AutoField(primary_key=True, verbose_name='主键')
    school_name = models.CharField(max_length=64, verbose_name='名称')

    class Meta:
        db_table = 'orm_school'
        verbose_name = '学校'
        verbose_name_plural = verbose_name
        pass

    pass


class Teacher(BaseModel):
    teacher_id = models.AutoField(primary_key=True, verbose_name='主键')
    teacher_name = models.CharField(max_length=16, verbose_name='姓名')

    # school_id = models.ForeignKey(to=School, on_delete=models.DO_NOTHING,
    #                               related_name='school_list', related_query_name='school',
    #                               null=True, blank=True,
    #                               verbose_name='学校')

    class Meta:
        db_table = 'orm_teacher'
        verbose_name = '教师'
        verbose_name_plural = verbose_name
        pass

    pass


# class Student(Base):
#     student_id = models.AutoField(primary_key=True, verbose_name='主键')
#     student_name = models.CharField(max_length=16, verbose_name='姓名')
#     sex = models.IntegerField(default=0, verbose_name='性别', choices=((-1, '女性'), (0, '未知',), (1, '男性'),), )
#     age = models.IntegerField(verbose_name='年龄')
#
#     school_id = models.ForeignKey(to=School, on_delete=models.DO_NOTHING,
#                                   related_name='school_list', related_query_name='school',
#                                   null=True, blank=True,
#                                   verbose_name='学校')
#
#     grade_class_id = models.ForeignKey(to=GradeClass, on_delete=models.DO_NOTHING,
#                                        related_name='grade_class_list', related_query_name='grade_class',
#                                        null=True, blank=True,
#                                        verbose_name='班级')
#
#     class Meta:
#         db_table = 'orm_student'
#         verbose_name = '学生'
#         verbose_name_plural = verbose_name
#         pass
#
#     pass